package com.example.asus.android_profiler;

import android.content.Intent;
import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;


public class MainActivity extends AppCompatActivity {
    //错误写法
    public static Activity activity;
    //正确写法
    //public static WeakReference<Activity>activity;
    //WeakReference解析
    //https://blog.csdn.net/matrix_xu/article/details/8424038

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        /*
        Button bt=findViewById(R.id.bt);
        bt.setText("内存泄露");
        bt.setOnClickListener(new ButtonOnClickListener());
        */
    }


    private void initView()
    {
        Button bt=findViewById(R.id.bt);
        bt.setText("内存泄露");
        bt.setOnClickListener(new ButtonOnClickListener());
    }

    class ButtonOnClickListener implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setClass(MainActivity.this,other.class);
            MainActivity.this.startActivity(intent);
        }
    }
}
